<?php

class Groupgallery extends BaseGroupgallery
{
public function __toString() {
	
	    if($this->getGallery())
	    {
	       $str = image_tag('/uploads/users/gallery/thumbnail/'.$this->getGallery()->getPhotoPath());
	    }
	    else 
	    {
	    	$str =image_tag('/images/no_logo_gallery.jpg');
	    }
		return $str;
	}
	
	
	 public function delete(PropelPDO $con = null)
  {
  	  ///Удаляем  фотки
  	  
  	$photos = $this->getGallerys();
  	foreach($photos as $p)
  	{    
	    $p->delete();
  	 } 	 
  	 parent::delete();
  }
	
	
	 public function getLogoLinkShow()
  {
  	 if($this->getLogoId()>0)
  	 {
  	 	$p = GalleryPeer::retrieveByPK($this->getLogoId());
  	 	$str = link_to(image_tag('/uploads/users/gallery/thumbnail/'.$p->getPhotoPath()),'@user_gallery_show?id='.$this->getId());
  	 }
  	 else 
  	 {
  	 	$str = link_to(image_tag('/images/no_logo_gallery.jpg'),'@user_gallery_show?id='.$this->getId());
  	 }
  	 return $str;
  	
  }
  
	 public function getLogoUrl()
  {
  	 if($this->getLogoId()>0)
  	 {
  	 	$p = GalleryPeer::retrieveByPK($this->getLogoId());
  	 	if($p)
  	 	{
  	 	  $str = '/uploads/users/gallery/thumbnail/'.$p->getPhotoPath();
  	 	}
  	 	else 
  	 	{
  	 		$str = '/images/no_logo_gallery.jpg';
  	 	}
  	 }
  	 else 
  	 {
  	 	$str = '/images/no_logo_gallery.jpg';
  	 }
  	 return $str;
  	
  }
  
  
	 public function getLogoLinkEdit()
  {
  	 if($this->getLogoId()>0)
  	 {
  	 	$p = GalleryPeer::retrieveByPK($this->getLogoId());
  	 	$str = link_to(image_tag('/uploads/users/gallery/thumbnail/'.$p->getPhotoPath()),'@gallery_edit?id='.$this->getId());
  	 }
  	 else 
  	 {
  	 	$str = link_to(image_tag('/images/no_logo_gallery.jpg'),'@gallery_edit?id='.$this->getId());
  	 }
  	 return $str;
  	
  }
  
  public function setPub($v)
	{
	  parent::setPub($v);
    
	   if($this->pub == 3)
	   {
	   	    //// Шлем уведомление
	   	  $user= $this->getsfGuardUser();  	
	      $not=MailnoticePeer::retrieveByPK(4);  
	      if($not)
	      {  
	      $title = $not->getTitle();
	      $body=$not->parse_body(array(
	          '%name%'=>$this->getName()
	      ));
	      myTools::sendMail($user->getEmail(),$title,$body);	
	      }
	      /////
	   }
    	  
	}
  
}
